from django.forms import ModelForm

from xadmin.models import UserProfile


class UserProfileForm(ModelForm):
    class Meta:
        model = UserProfile
        fields = ('username', 'password', 'is_superuser', 'chinese_name', 'email', 'is_staff',
                  'is_active', 'mobile')
        help_texts = {
            'is_active': '指定这个用户是否可以登录'
        }

    def __init__(self, *args, **kwargs):
        super(UserProfileForm, self).__init__(*args, **kwargs)
        no_style_colum = ('is_staff', 'is_active', 'is_superuser')
        for field_name in self.fields:
            field = self.fields[field_name]
            if field_name not in no_style_colum:
                field.widget.attrs.update({'class': 'layui-input'})
            else:
                field.widget.attrs.update({'lay-skin': 'primary', 'title': field.help_text})


class UserProfileEditFrom(ModelForm):
    class Meta:
        model = UserProfile
        fields = ('username', 'is_superuser', 'chinese_name', 'email', 'is_staff',
                  'is_active', 'mobile')
        help_texts = {
            'is_active': '指定这个用户是否可以登录'
        }

    def __init__(self, *args, **kwargs):
        super(UserProfileEditFrom, self).__init__(*args, **kwargs)
        no_style_colum = ('is_staff', 'is_active', 'is_superuser')
        for field_name in self.fields:
            field = self.fields[field_name]
            if field_name not in no_style_colum:
                field.widget.attrs.update({'class': 'layui-input'})
            else:
                field.widget.attrs.update({'lay-skin': 'primary', 'title': field.help_text})